import { ArticleData } from "./article";

export interface ResponseData {
  resultCode: number;
  message: string;
  data: any;
}

export type LastedArticleRetData = {
  sourceSelected: string;
  selected: string;
  rawData: ArticleData[];
  data: ArticleData[];
  sort: any
}

export interface LpNewHighDetail {
  rawData: [];
  data: any[]; 
  stat: [];
  selected: string;
  stocks: string[];
  options: [];
  sort: any
}

export interface WeekLpNewHighDetail extends LpNewHighDetail {
}

export interface WeekLpUpDetail extends LpNewHighDetail {
}

export interface WeekUp300Detail extends LpNewHighDetail {
}

export interface WeekDown300Detail extends LpNewHighDetail {
}

export interface MonthLpNewHighDetail extends LpNewHighDetail {
}

export interface MonthLpDownDetail extends LpNewHighDetail {
}

export interface MonthLpUpDetail extends LpNewHighDetail {
}

export function builtData(state: LpNewHighDetail, res : any) {

  state.options = res.data.dates
  state.rawData = res.data.data
  state.stat = res.data.stat

  state.stocks = Object.keys(state.rawData)

  // 最大记录数
  let maxRecord = 0
  let maxStock = ''
  state.stocks.forEach(stock => {
      if (maxRecord < state.rawData[stock].length) {
          maxRecord = state.rawData[stock].length
          maxStock = stock
      }
  })

  let tableDataMap = new Map()
  // 设置初始值
  state.rawData[maxStock].forEach(item => {
      let tmp = {} 
      tmp['date'] = item.date 
      state.stocks.forEach(stock => {
          tmp[stock] = null
      })
      tableDataMap.set(item.date,  tmp)
  })

  state.stocks.forEach(stock => {
      state.rawData[stock].forEach(item => {
          tableDataMap.get(item.date)[stock] = item
      })
  })
  state.data = Array.from(tableDataMap.values())
}